package com.campuscarbooking.api.controller;

import com.campuscarbooking.api.dto.ApiResponse;
import com.campuscarbooking.api.dto.BusScheduleDTO;
import com.campuscarbooking.api.dto.PageResponse;
import com.campuscarbooking.api.model.BusSchedule;
import com.campuscarbooking.api.service.BusScheduleService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/bus-schedules")
@RequiredArgsConstructor
public class BusScheduleController {

    private final BusScheduleService busScheduleService;

    @GetMapping
    public ApiResponse<PageResponse<BusScheduleDTO>> getSchedules(
            @RequestParam(required = false) String routeDirection,
            @RequestParam(required = false) Boolean isFixed,
            @RequestParam(defaultValue = "0") int page,
            @RequestParam(defaultValue = "10") int pageSize) {

        BusSchedule.RouteDirection direction = routeDirection != null
                ? BusSchedule.RouteDirection.valueOf(routeDirection)
                : null;

        return ApiResponse.success(busScheduleService.getSchedules(
                direction, isFixed, page, pageSize));
    }

    @GetMapping("/{id}")
    public ApiResponse<BusScheduleDTO> getScheduleById(@PathVariable Long id) {
        return ApiResponse.success(busScheduleService.getScheduleById(id));
    }
} 